package com.woniuxy.ticketmovie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.ticketmovie.entity.TicketType;
import com.woniuxy.ticketmovie.mapper.TypeMapper;
import com.woniuxy.ticketmovie.service.TypeService;
import com.woniuxy.ticketmovie.exception.NameExsitException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @ClassName TypeServiceImpl
 * @Description TODO
 * @Author zx
 * @Date 2021-02-22 22:16:15
 * @Version 1.0
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, TicketType> implements TypeService {

    @Resource
    private TypeMapper typeMapper;

    @Transactional
    @Override
    public void add(TicketType ticketType) {
        //查询条件封装
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name", ticketType.getName());
        if (typeMapper.selectCount(queryWrapper)==0){
            typeMapper.insert(ticketType);
        }else {
            throw new NameExsitException("");
        }
    }


    @Override
    public void update(TicketType ticketType) {
        //判断要修改的名称不能于其他类型名相同

    }
}
